package cn.lyq.card.data.src

/**
 * 将网络调用的状态传给UI层
 * @param message 可以是简单的字符串，如果业务复杂需要用状态码，可以使用Int，甚至于Pair,Triple
 */
class Result<out T>(val status: Status, val data: T?, val message: MyMsg) {
    companion object {
        fun <T> success(data: T?) = Result(
            Status.SUCCESS,
            data,
            MyMsg("")
        )

        fun <T> errorExpend(msg: Any?, data: T? = null) = Result(
            Status.ERROR,
            data,
            MyMsg("", msg)
        )

        fun <T> error(msg: String, data: T? = null) = Result(
            Status.ERROR,
            data,
            msg.toMsg()
        )

        fun <T> loading(msg: String, data: T? = null) = Result(
            Status.LOADING,
            data,
            msg.toMsg()
        )
    }

    fun requireData() = data!!
}